<%-- 
    Document   : programacionItinerario
    Created on : 27/05/2014, 04:57:23 PM
    Author     : USUARIO
--%>

<%@page import="java.util.Date"%>
<%@page import="java.util.Calendar"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>AdminLTE | Dashboard</title>
        <meta content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no' name='viewport'>
        <!-- bootstrap 3.0.2 -->
        <link href="../../css/bootstrap.min.css" rel="stylesheet" type="text/css" />
        <!-- font Awesome -->
        <link href="../../css/font-awesome.min.css" rel="stylesheet" type="text/css" />
        <!-- Ionicons -->
        <link href="../../css/ionicons.min.css" rel="stylesheet" type="text/css" />
        <!-- Theme style -->
        <link href="../../css/AdminLTE.css" rel="stylesheet" type="text/css" />
        <!-- DATA TABLES -->
        <link href="../../css/datatables/dataTables.bootstrap.css" rel="stylesheet" type="text/css" />
        
        <script type="text/javascript">
            function mostrarItinerario()
            {   var idAge = $("#idAgencia").val();
                var idRG = $("#idRG").val();
                $("#divIti").load("../../ServletProgramacion?accion=showIti",{idAge:idAge,idRG:idRG});
            }
        </script>
        
    </head>
    <body class="skin-blue">               
        
        <!-- header logo: style can be found in header.less -->
        <%@include file="../../jspf/header.jspf" %>
        <!-- header logo: style can be found in header.less -->
        
        
        <div class="wrapper row-offcanvas row-offcanvas-left">
            <!-- Left side column. contains the logo and sidebar -->
            <aside class="left-side sidebar-offcanvas">                
                <!-- sidebar: style can be found in sidebar.less -->
                <section class="sidebar">
                    <!-- Sidebar user panel -->
                    <div class="user-panel">
                        <div class="pull-left image">
                            <img src="../../img/avatar3.png" class="img-circle" alt="User Image" />
                        </div>
                        <div class="pull-left info">
                            <p>Hello, Jane</p>

                            <a href="#"><i class="fa fa-circle text-success"></i> Online</a>
                        </div>
                    </div>
                    <!-- search form -->
                    <form action="#" method="get" class="sidebar-form">
                        <div class="input-group">
                            <input type="text" name="q" class="form-control" placeholder="Search..."/>
                            <span class="input-group-btn">
                                <button type='submit' name='seach' id='search-btn' class="btn btn-flat"><i class="fa fa-search"></i></button>
                            </span>
                        </div>
                    </form>
                    <!-- /.search form -->
                    
                    <!-- sidebar menu: : style can be found in sidebar.less -->
                    <%@include file="../../jspf/menu.jspf" %>
                    <!-- sidebar menu: : style can be found in sidebar.less -->
                    
                </section>
                <!-- /.sidebar -->
            </aside>

            <!-- Right side column. Contains the navbar and content of the page -->
            <aside class="right-side">                
                <!-- Content Header (Page header) -->
                <section class="content-header">
                    <h1>
                        Itinerario
                        <small>Programación</small>
                    </h1>
                    <ol class="breadcrumb">
                        <li><a href="#"><i class="fa fa-dashboard"></i> Dashboard</a></li>
                        <li class="active">Itinerario</li>
                    </ol>
                </section>

                <!-- Main content -->
                <section class="content">                    
                    <% String msg = request.getParameter("msg");
                        if(msg!=null)
                        {
                    %>
                    <div class="col-xs-7">
                        <div class="alert alert-success alert-dismissable">
                            <i class="fa fa-check"></i>
                            <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times</button>
                            <b>Confirmación!&nbsp;</b> <%=msg%>
                        </div>
                    </div>
                    <%
                        }
                    %>
                    <div class="row">
                        <div class="col-xs-12">
                            <div class="box box-primary">
                                <%  Calendar c = Calendar.getInstance();
                                    String dia = Integer.toString(c.get(Calendar.DAY_OF_MONTH));
                                    int mes = c.get(Calendar.MONTH);
                                    mes = mes+1;
                                    String mese;
                                    //String mes = Integer.toString(c.get(Calendar.MONTH));
                                    if(mes>=1 && mes<=9)
                                    {   mese = "0"+mes; }
                                    else { mese = Integer.toString(mes);  }                                            
                                    String ano = Integer.toString(c.get(Calendar.YEAR));
                                    String fecha = ano+"-"+mese+"-"+dia;
                                    /*****************************************************************************************/
                                    boolean rpt = new ModIti_RangoDisponibilidad().validarRango(fecha);
                                    if(rpt)
                                    {   ModIti_RangoDisponibilidad rg = new ModIti_RangoDisponibilidad().obtenerRango(fecha);
                                        String fi, ff;
                                        SimpleDateFormat sd = new SimpleDateFormat("dd/MM/yyyy");
                                        fi = sd.format(rg.getFechainicio().getTime());
                                        ff = sd.format(rg.getFechafin().getTime());
                                %>
                                <div class="box-header" style="border-bottom:1px solid #0072b1;margin-bottom:15px;padding-bottom:1px;">
                                    <h2 class="box-title" style="margin-right:30px;font-size:25px;color: #0d70b7;">                                        
                                        Disponible desde: <b><%=fi%></b>&ensp;&#8211&ensp; hasta: <b><%=ff%></b>                                                                               
                                    </h2>
                                    <div class="list-group-item col-xs-5" style="float:right;">
                                        <form class="form-group">
                                            <div class="col-xs-9">
                                                <label>Fecha fin de disponibilidad</label>
                                                <input type="date" class="form-control" name="fecHas" required/>                                            
                                            </div>
                                            <div class="col-xs-3">
                                                <button type="submit" class="btn btn-default" style="padding:0px;">
                                                    <img src="../../img/calendar.png" width="60" height="60" title="Registrar fecha fin de disponibilidad"/>
                                                </button>
                                            </div>
                                        </form>
                                    </div><br/>
                                </div><!-- /.box-header -->                                
                                <div class="box-body table-responsive">
                                    
                                    <div class="row">
                                        <div class="col-xs-2">                                            
                                            <label>Programar en la agencia:</label>
                                        </div>
                                        <div class="col-xs-5">
                                            <input type="hidden" value="<%=rg.getId()%>" id="idRG"/>
                                            <select id="idAgencia" class="form-control">
                                                <option>Seleccione Agencia a programar itinerario</option>
                                                <% ArrayList<ModIti_Agencias> lis = new ModIti_Agencias().listarAgencias();
                                                   for(int i=0; i<lis.size(); i++)
                                                   {
                                                %>
                                                <option value="<%=lis.get(i).getId()%>"><%=lis.get(i).getNombre()%></option>
                                                <%
                                                   }
                                                %>                                                
                                            </select> 
                                        </div>
                                        <div class="col-xs-2">
                                            <button class="btn btn-default" type="button" onclick="mostrarItinerario()">
                                                Listar Itinerario
                                            </button>
                                        </div>
                                        <div class="col-xs-3">
                                            <label style="color:#04B404;font-weight:bold;">Fila de texto color verde </label>&ensp;<label> &#9658; Programado</label><br/>
                                            <label style="color:red;font-weight:bold;">Fila de texto color rojo </label>&ensp;<label> &#9658; Sin Programar</label>
                                        </div>
                                    </div><br/><br/>
                                    
                                    <div id="divIti">
                                    </div>
                                    
                                    <%--
                                    <table id="example1" class="table table-bordered table-striped">
                                        <thead>
                                            <tr>
                                                <th>Hora</th>
                                                <th>Servicio y Rutas</th>
                                                <th>Acciones de Programación</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <% 
                                               ModIti_Itinerario it = new ModIti_Itinerario();
                                               ArrayList<ModIti_Itinerario> listHo = new ArrayList<ModIti_Itinerario>();
                                               listHo = it.listarItinerarios();
                                               String h = null;
                                               SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
                                               for(int i=0; i<listHo.size(); i++)
                                               {
                                                   h = sdf.format(listHo.get(i).getHorasalida().getTime());
                                                   ModIti_Servicios s = new ModIti_Servicios().listarServicios(listHo.get(i).getFk_idservicio());
                                                   ModIti_Ruta r = new ModIti_Ruta().listarRutasOne(s.getFk_Idruta());
                                                   boolean ok = new ModIti_Programacion().estaProgramadoByIdItinerario(listHo.get(i).getIditinerario());
                                                   if(ok)
                                                   {    ModIti_Programacion pr = new ModIti_Programacion().obtenerProgramacionByIdItinerario(listHo.get(i).getIditinerario());
                                                        ArrayList<ModIti_Dias> dias = new ModIti_Dias().obtenerDiaByIdProgramacion(pr.getIdprogramacion());
                                            %> 
                                            <tr style="color:#04B404;font-weight:bold;">
                                                <td><%=h%></td>                                                
                                                <td>Servicio <%=s.getNombre()%>&ensp; | &ensp;<%=r.getOrigen()%> &#8211; <%=r.getDestino()%>&ensp; | &ensp;
                                                    <%
                                                    for(int y=0; y<dias.size(); y++)
                                                    {
                                                    %>  <%=dias.get(y).getDia().substring(0, 3)%> &ensp; 
                                                    <%
                                                    }
                                                       ModEmp_Empleado em = new ModEmp_Empleado().obtenerEmpleadoByID(pr.getFk_idempleado()); 
                                                       ModEmp_Persona per = new ModEmp_Persona().obtenerPersona(em.getFk_idpersona());
                                                    %>
                                                    | &ensp;<%=per.getApepaterno()%> <%=per.getApematerno()%> <%=per.getNombre()%> &ensp;
                                                    <%ModVeh_Vehiculo v = new ModVeh_Vehiculo().ObtenerVehiculoById(pr.getFk_idvehiculo());
                                                    %>
                                                    | &ensp; Placa: <%=v.getPlaca()%>
                                                </td>
                                                <td>
                                                    <a href="#">
                                                        <button type="button" style="background:none;border:none;" title="Editar Programación">
                                                            <img src="../../img/edit.png" width="24" height="24"/>
                                                        </button>
                                                    </a>
                                                </td>
                                            </tr>
                                            <%
                                                   } else
                                                   {
                                            %>
                                            <tr style="color:red;font-weight:bold;">
                                                <td><%=h%></td>                                                
                                                <td>Servicio <%=s.getNombre()%>&ensp; | &ensp;<%=r.getOrigen()%> &#8211; <%=r.getDestino()%>
                                                </td>
                                                <td>
                                                    <a href="programacionItinerario2.jsp?idI=<%=listHo.get(i).getIditinerario()%>&idS=<%=s.getId()%>&idR=<%=r.getId()%>&idRG=<%=rg.getId()%>">
                                                        <button type="button" style="background:none;border:none;" title="Programar servicio">
                                                            <img src="../../img/schedule.png" width="24" height="24"/>
                                                        </button>
                                                    </a>
                                                </td>
                                            </tr>
                                            <%
                                                   }
                                               }
                                            %>                                            
                                        </tbody>
                                        <tfoot>
                                            <tr>
                                                <th>Hora</th>
                                                <th>Servicio y Rutas</th>
                                                <th>Acciones de Programación</th>
                                            </tr>
                                        </tfoot>
                                    </table>
                                    --%>    
                                    
                                </div><!-- /.box-body --> 
                                <%
                                    } else
                                    {
                                %>
                                <div class="box-header" style="border-bottom:1px solid #0072b1;margin-bottom:15px;padding-bottom:1px;">
                                    <h2 class="box-title text-info" style="margin-right:30px;font-size:25px;">                                        
                                        <b>No se encuentra programacion, registrelo</b>                                                                              
                                    </h2>
                                    <div class="list-group-item col-xs-5" style="float:right;">
                                        <form class="form-group" action="../../controlador" method="post">                                            
                                            <input type="hidden" value="operRanFec" name="accion"/>
                                            <input type="hidden" value="I" name="accionBD"/>
                                            <input type="hidden" value="1" name="userCrea"/>
                                            <div class="col-xs-9">
                                                <label>Fecha fin de disponibilidad</label>
                                                <input type="date" class="form-control" name="fecHas" required/>                                            
                                            </div>
                                            <div class="col-xs-3">
                                                <button type="submit" class="btn btn-default" style="padding:0px;">
                                                    <img src="../../img/calendar.png" width="60" height="60" title="Registrar fecha fin de disponibilidad"/>
                                                </button>
                                            </div>
                                        </form>
                                    </div><br/>
                                </div>
                                <%
                                    }
                                %>
                            </div><!-- /.box -->
                        </div>
                    </div>                    
                </section><!-- /.content -->
            </aside><!-- /.right-side -->
        </div><!-- ./wrapper -->


        <!-- jQuery 2.0.2 -->
        <script src="../../js/jquery.min.js"></script>
        <!-- Bootstrap -->
        <script src="../../js/bootstrap.min.js" type="text/javascript"></script>
        <!-- AdminLTE App -->
        <script src="../../js/app.js" type="text/javascript"></script>
        <!-- DATA TABLES SCRIPT -->
        <script src="../../js/datatables/jquery.dataTables.js" type="text/javascript"></script>
        <script src="../../js/datatables/dataTables.bootstrap.js" type="text/javascript"></script>
        <!-- page script -->
        <script type="text/javascript">
            $(function() {
                $("#example1").dataTable();
                $('#example2').dataTable({
                    "bPaginate": true,
                    "bLengthChange": false,
                    "bFilter": false,
                    "bSort": true,
                    "bInfo": true,
                    "bAutoWidth": false
                });
            });
        </script>
    </body>
</html>